﻿using System;
using System.Collections.Generic;
using UnityEngine;
using USClientKernel.Common.Utils;
using Object = UnityEngine.Object;


public class BaseObject : MonoBehaviour
{
    private Dictionary<string, AssetInfo> m_assetPool;
    protected Dictionary<string, AssetInfo> AssetPool
    {
        get
        {
            if (null == m_assetPool)
                m_assetPool = new Dictionary<string, AssetInfo>();
            return m_assetPool;
        }
    }


    protected Object LoadAssetSync(string _path)
    {
        AssetInfo assetInfo = null;
        Object obj = ResManager.Instance.Load(_path, out assetInfo);
        if (null != assetInfo)
            AssetPool.Add(_path, assetInfo);
        return obj;
    }


    protected void LoadAssetCoroutine(string _path, Action<Object> _loaded = null)
    {
        if (null == _loaded )
            _loaded = OnAseetLoaded;

        AssetInfo assetInfo = null;
        ResManager.Instance.LoadCoroutine(_path, _loaded, out assetInfo);

        if (null != assetInfo)
            AssetPool.Add(_path, assetInfo);
    }


    protected void LoadAssetAsync(string _path, Action<Object> _loaded = null, Action<float> _progress = null)
    {
        if (null == _loaded)
            _loaded = OnAseetLoaded;

        if (null == _progress)
            _progress = OnAseetLoadProgress;

        AssetInfo assetInfo = null;
        ResManager.Instance.LoadAsync(_path, _loaded, _progress, out assetInfo);

        if (null != assetInfo)
            AssetPool.Add(_path, assetInfo);
    }


    protected virtual void OnAseetLoadProgress(float _progress)
    {

    }


    protected virtual void OnAseetLoaded(Object _obj)
    {

    }


    protected virtual void OnDestroy()
    {

    }
}
